<template>
  <div id="attend-train" class="animate__animated animate__faster" v-if="show">
    <div
      :style="{ width: props.width ? props.width : null }"
      class="content animate__animated animate__slideInUp animate__faster"
    >
      <div class="title">{{ props.title }}</div>
      <img src="../../assets/img/index/attend-bg.png" alt="" srcset="" />
      <div class="close" @click="doClose">
        <CloseOutlined />
      </div>
      <div class="inner-box">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const show = ref<boolean>(false);
const props = defineProps(['title', 'width']);
watch(
  show,
  async (val) => {
    show.value = val;
    await nextTick();
    const el = document.querySelector('body') as HTMLBodyElement;
    el.style.overflowY = val ? 'hidden' : 'auto';
  },
  { immediate: true }
);
const doClose = () => {
  var element = document.querySelector('#attend-train') as HTMLDivElement;
  element.classList.add('animate__fadeOut'); // 添加动画类
  // 动画完成后移除元素
  element.addEventListener(
    'animationend',
    function () {
      element.style.display = 'none';
      show.value = false;
    },
    { once: true }
  );
};
defineExpose({
  show,
});
</script>

<style lang="scss" scoped>
#attend-train {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 999;
}

.content {
  width: 560px;
  min-height: 462px;
  background: #ffffff;
  border-radius: 3px 3px 3px 3px;
  padding: 88px 40px 40px 40px;
  box-sizing: border-box;
  position: relative;

  img {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
  }

  .close {
    position: absolute;
    right: 30px;
    top: 20px;
    cursor: pointer;
  }

  .inner-box {
  }

  .title {
    font-size: 24px;
    color: #2c3a50;
    position: absolute;
    top: 27px;
    left: 20px;
  }
}
</style>
